#!/bin/bash

if [ $# -ne 2 ]; then
    echo "Usage: $0 <directory> <nb_nodes>" >&2
    exit 1
fi

count_dir=$1
nb_nodes=$2

prefix=@CMAKE_INSTALL_PREFIX@

if [ ! -f $count_dir/summary.log ]; then
    echo "Cannot open file $count_dir/summary.log" >&2
    exit 1
fi

rm -f $count_dir/blocks.dat 2>/dev/null

while read index name size other ;do
    # don't process the symbols whose name contains [...] or /

    if echo "$name" |grep -v '[\[/]'  > /dev/null ; then
	echo "Running counters_to_binding.py $count_dir/counters_$index.dat $nb_nodes $name $size >> $count_dir/blocks.dat"
	$prefix/bin/counters_to_binding.py $count_dir/counters_$index.dat $nb_nodes $name $size >> $count_dir/blocks.dat
    fi
done< $count_dir/summary.log

